#include "Bullet.h"


Bullet::Bullet(Image image, float posX, float posY, float velX = 200.0, float velY = 200.0) {
	bulletPic = image;
	velocityX = velX;
	velocityY = velY;
	positionX = posX;
	positionY = posY;
	outOfBounds = false;
	float angle = atan2(velX, (-velY));
	bulletPic.setRadians(angle - PI / 2);
}

Bullet::~Bullet(void) {
}

void Bullet::setPosX(float posX) {
	positionX = posX;
	if (positionX > GAME_WIDTH || positionX < 0.0f) {
		outOfBounds = true;
	}
	else {
		outOfBounds = false;
	}
}

float Bullet::getPosX() {
	return positionX;
}

void Bullet::setPosY(float posY) {
	positionY = posY;
	if (positionY > GAME_HEIGHT || positionY < 0.0f) {
		outOfBounds = true;
	}
	else {
		outOfBounds = false;
	}
}

float Bullet::getPosY() {
	return positionY;
}

void Bullet::setVelX(float velX) {
	velocityX = velX;
	float angle = atan2(velocityX, (-velocityY));
	bulletPic.setRadians(angle - PI / 2);
}

float Bullet::getVelX() {
	return velocityX;
}

void Bullet::setVelY(float velY) {
	velocityY = velY;
	float angle = atan2(velocityX, (-velocityY));
	bulletPic.setRadians(angle - PI / 2);
}

float Bullet::getVelY() {
	return velocityY;
}

void Bullet::draw() {
	bulletPic.setX(positionX);
	bulletPic.setY(positionY);
	bulletPic.draw();
}

void Bullet::update(float frameTime) {
	positionX += velocityX * frameTime;
	positionY += velocityY * frameTime;
	bulletPic.setX(positionX);
	bulletPic.setY(positionY);
	if (positionX > GAME_WIDTH || positionX < 0.0f) {
		outOfBounds = true;
	}
	else if (positionY > GAME_HEIGHT || positionY < 0.0f) {
		outOfBounds = true;
	}
	else {
		outOfBounds = false;
	}
}

bool Bullet::isOutOfBounds() {
	return outOfBounds;
}